import React, { useEffect, useState, useCallback } from "react";

const mockFetch = () => {
  return new Promise((re, rj) => {
    setTimeout(() => {
      re({ name: 1 });
    }, 3000);
  });
};

export function useInitData() {
  const [templateData, setTemplateData] = useState<any>({});
  const [loading, setLoading] = useState(true);

  const getData = useCallback(() => {
    setLoading(true);
    mockFetch()
      .then((data) => {
        setTemplateData(data);
      })
      .finally(() => {
        setLoading(false);
      });
  }, []);

  useEffect(() => {
    console.log("getData");
    getData();
  }, []);

  return { loading, templateData };
}
